import os
import platform

OS_NAME = platform.system();
LIB_DIR=os.environ['LIB_DIR'];
BIN_DIR=os.environ['BIN_DIR'];

sources= Glob('mvvm/base/*.c') + \
  Glob('mvvm/hardware/*.c') +  \
  Glob('mvvm/awtk/*.c') + \
  Glob('mvvm/cpp/*.cpp') + \
  Glob('mvvm/view_models/*.c') + \
  Glob('mvvm/*.c')

if 'WITH_JS' in os.environ and os.environ['WITH_JS'] == 'true':
  sources += Glob('mvvm/jerryscript/*.c')
if 'WITH_IOTJS' in os.environ and os.environ['WITH_IOTJS'] == 'true' :
  sources += Glob('mvvm/iotjs/*.c')

env=DefaultEnvironment().Clone()

EXPORT_DEF=''
if OS_NAME == 'Windows' :
  if os.environ['TOOLS_NAME'] == '' :
    EXPORT_DEF = ' /DEF:"src/mvvm.def" '
  elif os.environ['TOOLS_NAME'] == 'mingw' :
    EXPORT_DEF = ' "src/mvvm.def" '
	
print('EXPORT_DEF='+EXPORT_DEF)

if 'BUILD_SHARED' in os.environ and os.environ['BUILD_SHARED'] == 'True':
  LINKFLAGS=env['LINKFLAGS'] + EXPORT_DEF
  CFLAGS=env['CFLAGS']
  CCFLAGS=env['CCFLAGS']
  env.SharedLibrary(os.path.join(BIN_DIR, 'mvvm'), sources, LINKFLAGS=LINKFLAGS, CFLAGS=CFLAGS, CCFLAGS=CCFLAGS)
else:
  env.Library(os.path.join(LIB_DIR, 'mvvm'), sources)

